function get(url){
    return new Promise(function(resolve, reject){
        var req = new XMLHttpRequest();
        req.open('GET', url);
        req.onload = function(){
            if(req.status == 200){
                resolve(req.response);
            }else{
                reject(Error(req.statusText));
            }
        };
        req.onerror = function(){
            reject(Error("Network Error"));
        };
        req.send();
    });
}

function post(url, data){
    data = JSON.stringify(data);
    return new Promise(function(resolve, reject){
        var req = new XMLHttpRequest();
        req.open('POST', url);
        req.setRequestHeader('Content-Type', 'application/json');
        req.onload = function(){
            if(req.status == 200){
                resolve(req.response);
            }else{
                reject(Error(req.statusText));
            }
        };
        req.onerror = function(){
            reject(Error("Network Error"));
        };
        req.send(data);
    });
}

async function getEmbedNode(data){
    // console.log(data.nodes)
    result = new Object();
    await post("/postData",data).then(async function (response) {
        await get("/getEmbedNodeData").then(function (response) {
            result = JSON.parse(response);
        });
    });
    // console.log(result)
    return result;
}

async function getEmbedEdge(data){
    // console.log(data.nodes)
    result = new Object();
    await post("/postData",data).then(async function (response) {
        await get("/getEmbedEdgeData").then(function (response) {
            result = JSON.parse(response);
        });
    });
    // console.log(result)
    return result;
}

async function getCenterRelation(data){
    result = new Object();
    await post("/postData",data).then(async function (response) {
        await get("/getCenterRelation").then(function (response) {
            result = JSON.parse(response);
        });
    });
    // console.log(result)
    return result;
}

async function getFilteredData(condititon){
    result = new Object();
    await post("/postFilterCondition",condititon).then(async function (response) {
        await get("/getFilteredData").then(function (response) {
            result = JSON.parse(response);
        });
    });
    // console.log(result)
    return result;
}